local BaseWnd = require(SCRIPTS_DIR .. ".wnds.BaseWnd");
local EnterTableWnd = class("EnterTableWnd",BaseWnd);
function EnterTableWnd:ctor()
	EnterTableWnd.super.ctor(self);
end

function EnterTableWnd:onOpen()
    self:setButtonEvent()
    local group = self:widget("middle.group")
    group:setScale(0.01)
    mgrs.action:beginAction(group):ScaleTo(0.2,1.1):ScaleTo(0.1,1):endAction()
    self.num = ""
    self.strLen = 6
    self:initNumText()
end

function EnterTableWnd:initNumText()
    for i = 1,self.strLen do
        local num = self:widget("middle.group.text" .. i)
        if i <= string.len(self.num) then
            local str = string.sub(self.num,i,i)
            num:setString(str)
        else
            num:setString("")
        end
    end
end

function EnterTableWnd:setButtonEvent()
    -- body
    local close = self:widget("middle.group.close")
    self:createClick({targetNode = close}):clickHandler(function()
        self:closeAction()
    end);

    for i=0,11 do
        local num = self:widget("middle.group.num" .. i)
        self:createClick({targetNode = num}):clickHandler(function(param)
            self:buttonPress(param.index)
        end,{index = i});
    end
end

function EnterTableWnd:buttonPress(i)
    if i == 10 then
        self.num = ""
    elseif i == 11 then
        self.num = string.sub(self.num,1,string.len(self.num) - 1)
    elseif string.len(self.num) < self.strLen then
        self.num = self.num .. i;
    end
    mgrs.log:printDebug("click=%d result=%s",i,self.num)
    self:initNumText()
    if string.len(self.num) == self.strLen then
        mgrs.data:getLoginData():sendEnterTable(self.num)
    end
end

function EnterTableWnd:closeAction()
    -- body
    local group = self:widget("middle.group")
    mgrs.action:beginAction(group):ScaleTo(0.1,1.1):ScaleTo(0.3,0.01):CallFunc(function()
        self:close()
    end):endAction()
end

function EnterTableWnd:onClose()
	
end



------------------------------------------------------------------基础类调用-----------------------------------------------------------------------------
function EnterTableWnd:reqData(handler)
	handler(true);	
end

function EnterTableWnd:getLayer()
	return enums.Layer.Window;
end

function EnterTableWnd:getPreloadResList()
	return {};
end

function EnterTableWnd:getExclusiveType()
	return 0;
end

function EnterTableWnd:isOpenCloseSoundEnabled()
	return false;
end

function EnterTableWnd:onEnter()
	mgrs.log:printDebug("EnterTableWnd:onEnter");
end
function EnterTableWnd:onExit()
	mgrs.log:printDebug("EnterTableWnd:onExit");
end
function EnterTableWnd:onEnterTransitionFinish()
	mgrs.log:printDebug("EnterTableWnd:onEnterTransitionFinish");
end

function EnterTableWnd:onExitTransitionStart()
	mgrs.log:printDebug("EnterTableWnd:onExitTransitionStart");
end


mgrs.wnd:registerWnd(enums.Wnd.EnterTable,EnterTableWnd);

--endregion
